package regex;

 import org.junit.Test;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *开始字符          ^
 * 结束字符         $
 * 出现一次或多次   +        + 等效于 {1,}
 * 出现零次或多吃   *        * 等效于 {0,}
 * 出现零次或一吃   ?         ?等效于 {0,1}
 * 出现2次         {2}
 * 出现至少n次     {n,}
 * 匹配至少 n 次，至多 m 次            {n,m}
 */
public class test1 {

    //匹配字符串中出现某个字符几次
    @Test
    public void  sdfs(){
        String mes = "sdbghsbsgsbdyg";
        String mes2 = "sb";
        Pattern p = Pattern.compile(mes2);
        Matcher m = p.matcher(mes); // 获取 matcher 对象
        int count = 0;
        while(m.find()) {
            count++;
            System.out.println("Match number "+count);
            System.out.println("start(): "+m.start());
            System.out.println("end(): "+m.end());
        }
    }
    @Test
    public void test(){


//        boolean bo = Pattern.matches("^[0-9]{1,}$",sum);
//        boolean bo2 = Pattern.matches("[1]","1222");
          String s = "1234";
          System.out.println("bo2="+s.contains("1"));
//        System.out.println("bo2="+bo2);
//        System.out.println("a="+a);
//        System.out.println("b="+b);

    }
    @Test
    public void  sdddddfs(){
//        System.out.println("bo="+bo);
        String ss  ="ssss,ss,33";

        System.out.print(ss.contains("ssssss"));
        System.out.print(Pattern.matches("[a-zA-Z0-9\u4e00-\u9fa5]{6,16}","测试是啥"));
        System.out.print(Pattern.matches("[a-zA-Z0-9\u4e00-\u9fa5]{6,16}","111111"));
        System.out.print(Pattern.matches("((0\\.[0-9][0-9])|(0\\.[0-9][0-9])|([1-9]{1}[0-9]{0,8}\\.([0-9])[0-9])|(0))","9999.00"));
        String jfeerate = new BigDecimal("0.599").multiply(new BigDecimal(1)).setScale(2,BigDecimal.ROUND_HALF_UP).toString();

        DecimalFormat df = new DecimalFormat("##0.00");
        double d = 123.9078;
        String db = df.format(d);
        System.out.println(db);


    }
    @Test
   public void teste(){
       String ss ="[a-zA-Z0-9\u4e00-\u9fa5]{6,16}";
        //第一种  Pattern.matches(ss,"11111");
       boolean ss1 = Pattern.matches(ss,"11111");
       System.out.print(ss1);
        // 手机号正则：1开头，3-9，任意9位数
        String MOBILE_REGEX = "1[3-9][0-9]{9}";
        String ss2 = "";
        //第二种 ss2.matches(MOBILE_REGEX)
        System.out.print(ss2.matches(MOBILE_REGEX));
        //第三种
        Pattern S_PATTERN = Pattern.compile("^400[0-9]{7}");
        System.out.println(S_PATTERN.matcher("400111111").matches());
   }
}
